<template>
	<view class="content">
		<utop></utop>
		<view class="timg">
			<image src="../../static/indexbcg.png" mode=""></image>
		</view>
		<view class="bimg">
			<image @click="sm" src="../../static/sm.png" mode=""></image>
			<view class="texts">
				点击扫描生产报工二维码
			</view>
		</view>
<!-- 		<view class="" style="
		border: 1px solid #eee;
		margin: 80rpx auto;
		width: 260rpx;
		padding: 4rpx 4rpx 4rpx 10rpx">
			<input v-model="id" type="text" placeholder="输入订单ID" @confirm="handleSm"/>
		</view> -->
	</view>
</template>

<script>
	import {
		getUserinfo
	} from '@/common/http.api.js'
	export default {
		data() {
			return {
				title: 'Hello',
				id:'',
				userInfo:{}
			}
		},
		onLoad(option) {
			console.log(option);
			//扫码进来 查看是否登录没登录去登录，登录过跳转到对应页面
			if(uni.getStorageSync('token')){
				getUserinfo().then(res=>{
					res.data.avatar = 'https://stone.heiwangke.net'+res.data.avatar
					this.userInfo = res.data
					uni.setStorageSync('userinfo', res.data)
					if(option.scene){
						this.id = option.scene.substring(3)
						this.handleSm()
					}
				})
			}else{
				uni.reLaunch({
					url: '/pages/login/login'
				})
			}
		
		},
		onShareAppMessage(res) {
			return {
				title: 'MZ水钻欢迎你！',
				path: `/pages/index/index`,
			}
		},
		onShareTimeline(res) {
			return {
				title: 'MZ水钻欢迎你！',
				path: `/pages/index/index`,
			}
		},
		methods: {
			gologin() {
				uni.reLaunch({
					url: '/pages/login/login'
				})
			},
			sm(){
				let that = this
				uni.scanCode({
					barCodeInput: true,
					onlyFromCamera: true,
					success: function(res) {
						if (res.errMsg == "scanCode:ok") {
				           that.id = res.path.substring( res.path.lastIndexOf('?') + 1,res.path.length).substring(9)
						   setTimeout(()=>{
							   that.handleSm()
						   },500)
						}
					},
				})
			},
			handleSm() {
				if(this.userInfo.type == 1){
					uni.redirectTo({
						url:`/pages/index/xspage?id=${this.id}`
					})
				}
				if(this.userInfo.type == 2){
					uni.redirectTo({
						url:`/pages/index/ympage?id=${this.id}`
					})
				}
				if(this.userInfo.type == 3){
					uni.redirectTo({
						url:`/pages/index/xppage?id=${this.id}`
					})
				}
				if(this.userInfo.type == 4){
					uni.redirectTo({
						url:`/pages/index/xzpage?id=${this.id}`
					})
				}
			
			}
		}
	}
</script>

<style lang="scss">
	.utop {
		width: 100%;
		height: 70rpx;
		line-height: 70rpx;
		padding: 0rpx 20rpx;
		display: flex;
		align-items: center;
		position: fixed;
		z-index: 9999;
		background-color: #fff;
		top: 0%;
		.u_left{
			display: flex;
			align-items: center;
			.uimg{
				width: 60rpx;
				height: 60rpx;
			}
			.texts{
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 32rpx;
				color: #1D2541;
				margin-left: 20rpx;
			}
			.tag{
				width: 74rpx;
				height: 36rpx;
				background: #1246C8;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 24rpx;
				color: #FFFFFF;
				line-height: 36rpx;
				text-align: center;
				margin: 0rpx 20rpx;
			}
			.usmimg{
				width: 46rpx;
				height: 46rpx;
			}
		}
		
	}
	.timg {
		width: 606rpx;
		height: 664rpx;
		margin: 10rpx auto;

		image {
			width: 606rpx;
			height: 664rpx;
		}
	}

	.bimg {
		width: 340rpx;
		height: 340rpx;
		margin: 50rpx auto;
		box-shadow: 0rpx 0rpx 20rpx 0rpx #CEE3FF;

		image {
			width: 340rpx;
			height: 340rpx;
		}

		.texts {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			color: #196AEB;
			line-height: 70rpx;
		}
	}
</style>